package player;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

import java.awt.*;
import java.io.*;

import javax.imageio.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;

import java.awt.image.BufferedImage;

class BetFrame extends JDialog{
	private JTextField txtBet;

	BetFrame(PlayerFrame frame){

		super(frame,false);
		setBounds(320,250,240,140);
		JPanel panel = new JPanel(new GridLayout(2,1,5,5));
		txtBet = new JTextField();
		JButton btnConfirm = new JButton("Confirm");
		btnConfirm.addActionListener(frame);
		panel.add(txtBet);
		panel.add(btnConfirm);
		add(panel);
	}
	public String getBet(){
		return txtBet.getText();
	}
	public void clear(){
		this.txtBet.setText("");
	}
}


public class PlayerFrame extends JFrame implements ActionListener
{
	
	private JPanel contentPane;
	private JPanel[] panels;
	private JLabel[] lblPlayers;
	private JLabel[] lblPlayersCoins;
	private JLabel[] lblPlayersBets;
	private JLabel[] lblPlayersExchangeCards;
	private JLabel lblMyCoins;
	private JLabel lblMyBet;
	private JLabel lblRound;
	private JLabel lblStake;
	private JLabel lblMaxBet;
	private JButton btnCheck;
	private JButton btnBet;
	private JButton btnRaise;
	private JButton btnCall;
	private JButton btnFold;
	private JButton btnAllin;
	private JButton btnExchange;
	private BetFrame betFrame;
	private String[] playersNames;
	private Listener listener;
    private JScrollPane scrollPane;
	private int counterPrev = 0; 
	private int counterNext = 0;
	private int myBet = 0;
	private int maxBet = 0;
	private int myCoins;
	private JTextArea txtaChatDisplay;
	private JTextField txtChat;
	private String myName;
    private ImageIcon[] cards;
    private BufferedImage[] cardsImages;
    private JToggleButton[] cardsButtons;
    private Border selectedCard = BorderFactory.createLineBorder(Color.blue, 2);
    private String cardSet;
    private JPanel mainPanel;
    private JPanel resultPanel;
    private JPanel[] playersPanels;
    private JLabel[][] playersCardsLabels;
    private JButton closingButton;



	/**
	 * Create the frame.
	 */
	public PlayerFrame(String name, Listener listener)
	{	
		this.myName = name;
		lblPlayers = new JLabel[5];
		lblPlayersCoins = new JLabel[5];
		lblPlayersBets = new JLabel[5];
		lblPlayersExchangeCards = new JLabel[5];
		panels = new JPanel[6];
        cards = new ImageIcon[56];
        cardsImages = new BufferedImage[56];
        cardsButtons = new JToggleButton[4];
		playersNames = new String[]{"","","","",""};
		this.listener = listener;
		this.betFrame = new BetFrame(this);
        final PlayerFrame temp = this;
        this.setTitle("Badugi");
	    this.setResizable(false);

	    resultPanel = new JPanel (new BorderLayout());
        mainPanel = new JPanel(new GridLayout(3,2,5,5));
        playersPanels = new JPanel[6];
        playersCardsLabels = new JLabel[6][4];
        closingButton = new JButton("Close");
        closingButton.addActionListener(this);
        
        for(int i = 0; i < 6; i++) {
            playersPanels[i] = new JPanel();
            playersPanels[i].setSize(72,400);
            playersPanels[i].setBackground(new Color(5,75,8));
            for(int j = 0; j < 4; j++) {
                playersCardsLabels[i][j] = new JLabel();
                playersCardsLabels[i][j].setHorizontalAlignment(JLabel.CENTER);
                playersCardsLabels[i][j].setVerticalAlignment(JLabel.CENTER);
                playersCardsLabels[i][j].setIcon(getCardIcon(52));
                playersPanels[i].add(playersCardsLabels[i][j]);
            }


            playersPanels[i].setLayout(new FlowLayout());
            mainPanel.add(playersPanels[i]);
        }
        mainPanel.setBackground(new Color(5,75,8));
        resultPanel.add(mainPanel,BorderLayout.CENTER);
        resultPanel.add(closingButton,BorderLayout.SOUTH);
        this.add(resultPanel);

        for(int i = 0; i < 4; i++) {
            cardsButtons[i] = new JToggleButton();
            cardsButtons[i].setActionCommand(Integer.toString(i));
            cardsButtons[i].addActionListener(this);
        }
        try {
            for(int i = 0; i < cardsImages.length; i++) {
                cards[i] = new ImageIcon();
                cardsImages[i] = ImageIO.read(new File("src\\images\\" + Integer.toString(i)+".gif"));
                cards[i].setImage(cardsImages[i]);
            }
        } catch (IOException e) {
            System.out.println("No such image");
        }
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setBackground(new Color(5,75,8));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel pnlChat = new JPanel();
		pnlChat.setBackground(new Color(9,47,5));
		pnlChat.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Chat", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 204, 51)));
		pnlChat.setBounds(594, 22, 278, 524);
		contentPane.add(pnlChat);
		pnlChat.setLayout(null);
		
		txtaChatDisplay = new JTextArea(23,27);
		scrollPane = new JScrollPane(txtaChatDisplay);
		txtaChatDisplay.setLineWrap(true);
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		txtaChatDisplay.setBackground(new Color(192, 192, 192));
		txtaChatDisplay.setEditable(false);
		scrollPane.setBounds(10, 16, 258, 410);
		pnlChat.add(scrollPane);
		
		txtChat = new JTextField("");
		txtChat.setBounds(10, 435, 258, 31);
		pnlChat.add(txtChat);
		
		JButton btnSend = new JButton("Send");
		btnSend.addActionListener(this);
		btnSend.setBounds(10, 474, 258, 40);
		pnlChat.add(btnSend);
		
		JPanel pnlMe = new JPanel();
		pnlMe.setBorder(new TitledBorder(null, name, TitledBorder.LEADING, TitledBorder.TOP, null, null));
		pnlMe.setBounds(26, 339, 541, 206);
		contentPane.add(pnlMe);
		pnlMe.setLayout(null);




		cardsButtons[0].setBounds(8, 103, 72, 96);
        cardsButtons[0].setHorizontalAlignment(SwingConstants.CENTER);
        cardsButtons[0].setIcon(cards[52]);
		pnlMe.add(cardsButtons[0]);


        cardsButtons[1].setBounds(92, 103, 72, 96);
        cardsButtons[1].setHorizontalAlignment(SwingConstants.CENTER);
        cardsButtons[1].setIcon(cards[52]);
		pnlMe.add(cardsButtons[1]);


        cardsButtons[2].setBounds(174, 103, 72, 96);
        cardsButtons[2].setHorizontalAlignment(SwingConstants.CENTER);
        cardsButtons[2].setIcon(cards[52]);
		pnlMe.add(cardsButtons[2]);


        cardsButtons[3].setBounds(256, 103, 72, 96);
        cardsButtons[3].setHorizontalAlignment(SwingConstants.CENTER);
        cardsButtons[3].setIcon(cards[52]);
		pnlMe.add(cardsButtons[3]);
		
		JPanel pnlButtons = new JPanel();
		pnlButtons.setBounds(428, 16, 105, 183);
		pnlMe.add(pnlButtons);
		pnlButtons.setLayout(new GridLayout(0, 1, 0, 0));
		
		btnCheck = new JButton("Check");
		btnCheck.addActionListener(this);
		pnlButtons.add(btnCheck);
		
		btnBet = new JButton("Bet");
		btnBet.addActionListener(this);
		pnlButtons.add(btnBet);
	
		btnRaise = new JButton("Raise");
		btnRaise.addActionListener(this);
		pnlButtons.add(btnRaise);
		
		btnCall = new JButton("Call");
		btnCall.addActionListener(this);
		pnlButtons.add(btnCall);
		
		btnFold = new JButton("Fold");
		btnFold.addActionListener(this);
		pnlButtons.add(btnFold);
		
		btnAllin = new JButton("All-in");
		btnAllin.addActionListener(this);
		pnlButtons.add(btnAllin);
		
		btnExchange = new JButton("Exchange");
		btnExchange.addActionListener(this);
		pnlButtons.add(btnExchange);
		
		JLabel lblNewLabel = new JLabel("My Coins:");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setBounds(8, 16, 87, 31);
		pnlMe.add(lblNewLabel);
		
		lblMyCoins = new JLabel("<AMOUNT>");
		lblMyCoins.setHorizontalAlignment(SwingConstants.CENTER);
		lblMyCoins.setBounds(95, 16, 105, 31);
		pnlMe.add(lblMyCoins);
		
		lblMyBet = new JLabel("0");
		lblMyBet.setHorizontalAlignment(SwingConstants.CENTER);
		lblMyBet.setBounds(313, 16, 105, 31);
		pnlMe.add(lblMyBet);
		
		JLabel lblNewLabel2 = new JLabel("My Bet:");
		lblNewLabel2.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel2.setBounds(225, 16, 87, 31);
		pnlMe.add(lblNewLabel2);
		
		JPanel pnlPlayers = new JPanel(new GridLayout(2, 3, 10, 10));
		pnlPlayers.setBounds(26, 22, 541, 292);
		pnlPlayers.setBackground(new Color(5,75,8));
		contentPane.add(pnlPlayers);
		
		for( int i=1; i<4; i++){
			panels[i]= new JPanel(new GridLayout(4,1));
			panels[i].setBackground(new Color(5,75,8));
            panels[i].setForeground(new Color(253, 253, 253));
			lblPlayers[i] = new JLabel("");
			lblPlayers[i].setHorizontalAlignment(SwingConstants.CENTER);
			lblPlayersCoins[i] = new JLabel();
			lblPlayersCoins[i].setHorizontalAlignment(SwingConstants.RIGHT);
			lblPlayersBets[i] = new JLabel();
			lblPlayersBets[i].setHorizontalAlignment(SwingConstants.RIGHT);
			lblPlayersBets[i].setForeground(Color.WHITE);
			lblPlayersExchangeCards[i] = new JLabel();
			//lblPlayersExchangeCards[i].setFont(new Font("Tahoma", Font.PLAIN, 8));
			panels[i].add(lblPlayers[i]);
			panels[i].add(lblPlayersCoins[i]);
			panels[i].add(lblPlayersBets[i]);
			panels[i].add(lblPlayersExchangeCards[i]);
			pnlPlayers.add(panels[i]);
		}
		
		panels[0]= new JPanel(new GridLayout(4,1));
		panels[0].setBackground(new Color(5,75,8));
        panels[0].setForeground(new Color(253, 253, 253));
		lblPlayers[0] = new JLabel("");
		lblPlayers[0].setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayersCoins[0] = new JLabel();
		lblPlayersCoins[0].setHorizontalAlignment(SwingConstants.RIGHT);
		lblPlayersBets[0] = new JLabel();
		lblPlayersBets[0].setHorizontalAlignment(SwingConstants.RIGHT);
		//lblPlayersBets[0].setVerticalAlignment(SwingConstants.TOP);
		//lblPlayersBets[0].setFont(new Font("Tahoma", Font.BOLD, 10));
		lblPlayersBets[0].setForeground(Color.WHITE);
		lblPlayersExchangeCards[0] = new JLabel();
		panels[0].add(lblPlayers[0]);
		panels[0].add(lblPlayersCoins[0]);
		panels[0].add(lblPlayersBets[0]);
		panels[0].add(lblPlayersExchangeCards[0]);
		pnlPlayers.add(panels[0]);
		
		panels[5] = new JPanel(new GridLayout(3, 1, 5, 5));
		panels[5].setBackground(new Color(5,75,8));
		
		lblRound = new JLabel("Round: 1");
		lblRound.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblRound.setForeground(new Color(50, 205, 50));
		lblRound.setBackground(new Color(9, 47, 5));
		lblRound.setOpaque(true);
		lblRound.setHorizontalAlignment(SwingConstants.CENTER);
		panels[5].add(lblRound);
		
		lblStake = new JLabel("Stawka");
		lblStake.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblStake.setForeground(new Color(50, 205, 50));
		lblStake.setBackground(new Color(9, 47, 5));
		lblStake.setOpaque(true);
		lblStake.setHorizontalAlignment(SwingConstants.CENTER);
		panels[5].add(lblStake);
		
		lblMaxBet = new JLabel("Max Bet");
		lblMaxBet.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblMaxBet.setForeground(new Color(50, 205, 50));
		lblMaxBet.setBackground(new Color(9, 47, 5));
		lblMaxBet.setOpaque(true);
		lblMaxBet.setHorizontalAlignment(SwingConstants.CENTER);
		panels[5].add(lblMaxBet);
		
		pnlPlayers.add(panels[5]);
		
		panels[4]= new JPanel(new GridLayout(4,1));
		panels[4].setBackground(new Color(5,75,8));
        panels[4].setForeground(new Color(253, 253, 253));
		lblPlayers[4] = new JLabel("");
		lblPlayers[4].setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayersCoins[4] = new JLabel();
		lblPlayersBets[4] = new JLabel();
		lblPlayersCoins[4].setHorizontalAlignment(SwingConstants.RIGHT);
		lblPlayersBets[4].setHorizontalAlignment(SwingConstants.RIGHT);
		//lblPlayersBets[4].setVerticalAlignment(SwingConstants.TOP);
		//lblPlayersBets[4].setFont(new Font("Tahoma", Font.BOLD, 10));
		lblPlayersBets[4].setForeground(Color.WHITE);
		lblPlayersExchangeCards[4] = new JLabel();
		panels[4].add(lblPlayers[4]);
		panels[4].add(lblPlayersCoins[4]);
		panels[4].add(lblPlayersBets[4]);
		panels[4].add(lblPlayersExchangeCards[4]);
		pnlPlayers.add(panels[4]);
		disableButtons();


}
	/** 
	 * @param name of player,which will display
	 * @param previous if the player join game before the owner of PlayerFrame
	 */
	public void setPlayer(String name, boolean previous){
		if(previous){
			lblPlayers[4-counterPrev].setText(name);
			playersNames[4-counterPrev] = name;
			panels[4-counterPrev].setBackground(new Color(0, 102, 0));
			panels[4-counterPrev].setOpaque(true);
			lblPlayersCoins[4-counterPrev].setText(lblMyCoins.getText());
			//lblPlayersCoins[4-counterPrev].setBackground(new Color(0, 102, 0));
			//lblPlayersCoins[4-counterPrev].setOpaque(true);
			//lblPlayersCoins[4-counterPrev].setVerticalAlignment(SwingConstants.NORTH_EAST);
			counterPrev++;
		}
		else{
			lblPlayers[counterNext].setText(name);
			playersNames[counterNext] = name;
			panels[counterNext].setBackground(new Color(0, 102, 0));
			panels[counterNext].setOpaque(true);
			lblPlayersCoins[counterNext].setText(lblMyCoins.getText());
			counterNext++;
		}
	}
    void displayPlayerHands(String[] playersHands, String winners) {
        /*
            String[i] := 15charOfName + 8charOfCards
            OR        := 15charOfName + "FOLDED"
        */
        int playerCards[][] = new int [playersHands.length][4];

        for(int i = 0; i < playersHands.length; i++) {
            if(playersHands[i].substring(15).equals("FOLDED**"))
                for(int j = 0; j < 4; j++) {
                    playersCardsLabels[i][j].setIcon(getCardIcon(52));
                    playerCards[i][j] = -1;
                }
            else
                for(int j = 0; j < 4; j++) {
                    System.out.println();
                    playerCards[i][j] = Integer.parseInt(playersHands[i].substring(15+2*j,17+2*j));
                    playersCardsLabels[i][j].setIcon(getCardIcon(playerCards[i][j]));
                }
            if(Character.toString(winners.charAt(i)).equals("W")) {
                playersPanels[i].setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), playersHands[i].substring(0, 15), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(211, 26, 244)));
                playersPanels[i].setBackground(new Color(25, 95, 28));
            }
            else {
                playersPanels[i].setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), playersHands[i].substring(0, 15), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(253, 253, 253)));
                playersPanels[i].setBackground(new Color(5,75,8));
            }
        }
        setContentPane(resultPanel);
        repaint();
    }
	public void setCoins(String name, String amount){
		if (name.equals(myName)){
			lblMyCoins.setText(amount);
			myCoins = Integer.parseInt(amount);
		}
		else{
			int i;
			for(i=0; i<5 && !playersNames[i].equals(name); i++){}
			if(i!=5)lblPlayersCoins[i].setText(amount);
		}
	}
	public void setBet(String name, String amount){
		int bet = Integer.parseInt(amount);
		if (bet>maxBet){
			maxBet=bet;
			lblMaxBet.setText("Max Bet: " + amount);
		}
		if (name.equals(myName)){
			lblMyBet.setText(amount);
			myBet = bet;
		}
		else{
			int i;
			for(i=0; i<5 && !playersNames[i].equals(name); i++){}
			if(i!=5)lblPlayersBets[i].setText(amount);
		}
	}
	public void setBigBlind(String name, String bBlind){
		int blind = Integer.parseInt(bBlind);
		maxBet = blind;
		lblMaxBet.setText("Max Bet: " +bBlind);
		if (name.equals(myName)){
			JOptionPane.showMessageDialog(null, "You have a big blind :" + bBlind,
					"Information", JOptionPane.INFORMATION_MESSAGE);
			lblMyBet.setText(bBlind);
			myBet = blind;
		}
		else{
			int i;
			for(i=0; i<5 && !playersNames[i].equals(name); i++){}
			if(i!=5){
				lblPlayers[i].setText(playersNames[i] + "(Big Blind)");
				lblPlayersBets[i].setText(bBlind);
			}
		}
	}
	public void setSmallBlind(String name,String sBlind){
		if (name.equals(myName)){
			int blind = Integer.parseInt(sBlind);
			JOptionPane.showMessageDialog(null, "You have a small blind: " + sBlind,
					"Information", JOptionPane.INFORMATION_MESSAGE);
			lblMyBet.setText(sBlind);
			myBet = blind;
		}
		else{
			int i;
			for(i=0; i<5 && !playersNames[i].equals(name); i++){}
			if(i!=5){
				lblPlayers[i].setText(playersNames[i] + "(Small Blind)");
				lblPlayersBets[i].setText(sBlind);
			}
		}
	}
	public void displayAmountOfExchangedCards(String name, String amount){
		int i;
		for( i=0; i<5 && !playersNames[i].equals(name); i++){}
		if(i!=5){
			lblPlayersExchangeCards[i].setText("Cards Exchanged in round:" + amount);
		}
	}
	public void displayMessage(String message){
		txtaChatDisplay.append(message+"\n");
        txtaChatDisplay.setCaretPosition(txtaChatDisplay.getDocument().getLength());
        //Auto scroll here

	}
	public void enableButtons(String buttons){
		System.out.println(buttons + "<");
		while(!buttons.equals("")){
			if (buttons.startsWith("E")){
				btnExchange.setEnabled(true);
				System.out.println(btnExchange.isEnabled());
				System.out.println("EnableButtons in frame");
			}
			else if (buttons.startsWith("H"))
				btnCheck.setEnabled(true);
			else if (buttons.startsWith("B"))
				btnBet.setEnabled(true);
			else if (buttons.startsWith("R"))
				btnRaise.setEnabled(true);
			else if (buttons.startsWith("C"))
				btnCall.setEnabled(true);
			else if (buttons.startsWith("F"))
				btnFold.setEnabled(true);
			else if (buttons.startsWith("A"))
				btnAllin.setEnabled(true);
			else if (buttons.startsWith("N"))
				btnExchange.setEnabled(true);//?
			buttons = buttons.substring(1);
		}
	}
	public void disableButtons(){
			btnCheck.setEnabled(false);
			btnBet.setEnabled(false);
			btnRaise.setEnabled(false);
			btnCall.setEnabled(false);
			btnFold.setEnabled(false);
			btnAllin.setEnabled(false);
			btnExchange.setEnabled(false);
	}

	public void displayFold(String name){
		if (name.equals(myName)){
			lblMyBet.setText("You Folded");
		}
		else{
			int i;
			for(i=0; i<5 && !playersNames[i].equals(name); i++){}
			if(i!=5)lblPlayersBets[i].setText("Folded");
		}
	}
	public void displayAllin(String name){
		if (name.equals(myName)){
			lblMyCoins.setText("All-in");
		}
		else{
			int i;
			for(i=0; i<5 && !playersNames[i].equals(name); i++){}
			if(i!=5)lblPlayersCoins[i].setText("All-in");
		}
	}
	public void displayStake(String stake){
		lblStake.setText("Stake: " + stake);
		for (int i = 0; i < 5; i++){
			lblPlayersExchangeCards[i].setText("");
		}
	}
	public void displayRound(String round){
		lblRound.setText("Round: " +round);
	}
	public void deletePlayer(String name){
		int i;
		for(i=0; i<5 && !playersNames[i].equals(name); i++){}
		if(i!=5){
			panels[i].setVisible(false);
		}
	}
    public void displayCards(int selectedCards[]) {
        for(int i = 0; i < 4; i++) {
            cardsButtons[i].setIcon(cards[selectedCards[i]]);
            this.repaint();
        }
    }
    public ImageIcon getCardIcon (int i) {
        return cards[i];
    }



	public void actionPerformed(ActionEvent e)
	{
		String s = e.getActionCommand();
		if (s.equals("Send")){
			String message = txtChat.getText();
			if(!message.equals("")){
				listener.sendMessage(message);
				txtChat.setText("");
			}
		}
		else if (s.equals("Check")){
			listener.sendCheck();
			disableButtons();
		}
		else if (s.equals("Raise") || s.equals("Bet")){
			betFrame.setVisible(true);
		}
		else if (s.equals("Confirm")){
			try{
				int temp = Integer.parseInt(betFrame.getBet());
				if( (temp+myBet)>maxBet && temp<=myCoins){
					listener.sendBet(temp);
					betFrame.setVisible(false);
					betFrame.clear();
					disableButtons();					
				}
				else{
					JOptionPane.showMessageDialog(null, "You should beat Max Bet" ,
						"Błąd", JOptionPane.ERROR_MESSAGE);
					betFrame.clear();
				}
			}
			catch(NumberFormatException ex){
				JOptionPane.showMessageDialog(null, "Incorrect data" ,
						"Błąd", JOptionPane.ERROR_MESSAGE);
					betFrame.clear();
			}
		}
		else if (s.equals("Call")){
			listener.sendBet(maxBet-myBet);
			disableButtons();
		}
		else if(s.equals("All-in")){
			listener.sendAllin();
			disableButtons();
		}
		else if(s.equals("Fold")){
			listener.sendFold();
			disableButtons();
		}
		else if(s.equals("Exchange")){
			cardSet  = "";
			for(int i = 0; i<4; i++){
				if(cardsButtons[i].getBorder().equals(selectedCard))
					cardSet = cardSet + "1";
		        else
		        	cardSet = cardSet + "0";
                cardsButtons[i].setBorder(BorderFactory.createEmptyBorder());
		    }
			listener.sendExchange(cardSet);
			disableButtons();
		}
		else if(s.equals("Close")){
			setContentPane(contentPane);
			listener.sendClose();
		}
		else if(s.equals("0")) {
           if(cardsButtons[0].getBorder().equals(selectedCard))
               cardsButtons[0].setBorder(BorderFactory.createEmptyBorder());
           else
               cardsButtons[0].setBorder(selectedCard);
        }
        else if(s.equals("1")) {
            if(cardsButtons[1].getBorder().equals(selectedCard))
                cardsButtons[1].setBorder(BorderFactory.createEmptyBorder());
            else
                cardsButtons[1].setBorder(selectedCard);
        }
        else if(s.equals("2")) {
            if(cardsButtons[2].getBorder().equals(selectedCard))
                cardsButtons[2].setBorder(BorderFactory.createEmptyBorder());
            else
                cardsButtons[2].setBorder(selectedCard);
        }
        else if(s.equals("3")) {
            if(cardsButtons[3].getBorder().equals(selectedCard))
                cardsButtons[3].setBorder(BorderFactory.createEmptyBorder());
            else
                cardsButtons[3].setBorder(selectedCard);
        }
	}
}
